/*     */ package com.asiainfo.dacp.stat.olapcheck;
/*     */ 
/*     */ import com.asiainfo.dacp.jdbc.JdbcTemplate;
/*     */ import com.asiainfo.dacp.util.JsonHelper;
/*     */ import java.io.PrintStream;
/*     */ import java.math.BigDecimal;
/*     */ import java.util.ArrayList;
/*     */ import java.util.Collections;
/*     */ import java.util.Comparator;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ import org.slf4j.Logger;
/*     */ import org.slf4j.LoggerFactory;
/*     */ 
/*     */ 
/*     */ public class DimInfo
/*     */ {
/*     */   private OlapInfo olapInfo;
/*     */   public String dimid;
/*     */   public String dimname;
/*     */   public String dimtype;
/*     */   public String fktab;
/*     */   public int memberNum;
/*     */   public int sampleMemberNum;
/*     */   public int opsampleMemberNum;
/*     */   public double val;
/*     */   public double pval;
/*     */   public double addval;
/*     */   public double drate;
/*     */   public double mrate;
/*  31 */   public int AddMemberNum = 0;
/*  32 */   public double AddMember_Val = 0.0D;
/*  33 */   public double AddMember_ValRate = 0.0D;
/*  34 */   public int DelMemberNum = 0;
/*  35 */   public double DelMember_Val = 0.0D;
/*  36 */   public double DelMember_ValRate = 0.0D;
/*     */   
/*     */   public int IncreaseMemberNum;
/*  39 */   public double Increase_SumVal = 0.0D;
/*  40 */   public String firstIncrease_Code = "";
/*  41 */   public double firstIncrease_Rate = -9999.0D;
/*     */   
/*     */   public double firstIncrease_ValScope;
/*     */   public double firstIncrease_ValRate;
/*     */   public int firstIncrease_RateIndex;
/*     */   public double firstIncrease_RatePos;
/*     */   public int DeclineMemberNum;
/*  48 */   public double Decline_SumVal = 0.0D;
/*  49 */   public String firstDecline_Code = "";
/*  50 */   public double firstDecline_Rate = 999.0D;
/*     */   
/*     */   public double firstDecline_ValScope;
/*     */   public double firstDecline_ValRate;
/*     */   public int firstDecline_RateIndex;
/*     */   public double firstDecline_RatePos;
/*  56 */   private String dimsql = "";
/*  57 */   public List<DimItemData> dimItemList = new ArrayList();
/*     */   
/*  59 */   private static Logger logger = LoggerFactory.getLogger(OlapInfo.class);
/*     */   
/*     */   public DimInfo(String dimid, OlapInfo olapInfo) {
/*  62 */     this.olapInfo = olapInfo;
/*  63 */     this.dimid = dimid;
/*     */   }
/*     */   
/*     */   public void proceDim(String dimsql, String dbname, String where) {
/*  67 */     this.val = this.olapInfo.val;
/*  68 */     this.pval = this.olapInfo.pval;
/*  69 */     this.addval = this.olapInfo.addval;
/*  70 */     this.drate = this.olapInfo.drate;
/*  71 */     this.mrate = this.olapInfo.mrate;
/*     */     
/*     */ 
/*  74 */     JdbcTemplate jdbcTemplate = new JdbcTemplate(dbname);
/*  75 */     List dimData = jdbcTemplate.queryForList(dimsql);
/*  76 */     this.memberNum = dimData.size();
/*     */     
/*     */ 
/*  79 */     for (int i = 0; i < dimData.size(); i++) {
/*  80 */       Map itemMap = (Map)dimData.get(i);
/*  81 */       DimItemData itemData = new DimItemData(itemMap, this.dimid);
/*  82 */       this.dimItemList.add(itemData);
/*     */       
/*  84 */       itemData.ADDVAL_PARTRATE = MathUtil.divide(Double.valueOf(itemData.ADDVAL), Double.valueOf(this.addval)).doubleValue();
/*  85 */       itemData.OP_SUMRATE = MathUtil.divide(Double.valueOf(itemData.DRATE), Double.valueOf(this.drate)).doubleValue();
/*  86 */       if (itemData.OP_SUMRATE > 0.0D) {
/*  87 */         this.sampleMemberNum += 1;
/*     */       } else {
/*  89 */         this.opsampleMemberNum += 1;
/*     */       }
/*     */       
/*  92 */       if (itemData.ISNEW == "add") {
/*  93 */         this.AddMemberNum += 1;
/*  94 */         this.AddMember_Val = MathUtil.add(Double.valueOf(this.AddMember_Val), Double.valueOf(itemData.VAL)).doubleValue();
/*     */       }
/*  96 */       else if (itemData.ISNEW == "del") {
/*  97 */         this.DelMemberNum += 1;
/*  98 */         this.DelMember_Val = MathUtil.add(Double.valueOf(this.DelMember_Val), Double.valueOf(itemData.PVAL)).doubleValue();
/*     */       }
/* 100 */       if (itemData.DRATE >= 0.0D) {
/* 101 */         this.IncreaseMemberNum += 1;
/* 102 */         this.Increase_SumVal = MathUtil.add(Double.valueOf(this.Increase_SumVal), Double.valueOf(itemData.ADDVAL)).doubleValue();
/*     */ 
/*     */       }
/* 105 */       else if (itemData.DRATE < 0.0D) {
/* 106 */         this.DeclineMemberNum += 1;
/* 107 */         this.Decline_SumVal = MathUtil.add(Double.valueOf(this.Decline_SumVal), Double.valueOf(itemData.ADDVAL)).doubleValue();
/*     */       }
/*     */     }
/*     */     
/*     */ 
/*     */ 
/* 113 */     sortItemData("VAL", "VAL_INDEX");
/*     */     
/* 115 */     sortItemData("PVAL", "PVAL_INDEX");
/*     */     
/*     */ 
/* 118 */     sortItemData("DRATE", "DRATE_INDEX");
/*     */     
/* 120 */     for (int i = 0; i < this.dimItemList.size(); i++) {
/* 121 */       DimItemData itemData = (DimItemData)this.dimItemList.get(i);
/* 122 */       itemData.VAL_INDEXCHG = (itemData.VAL_INDEX - itemData.PVAL_INDEX);
/* 123 */       if (itemData.DRATE >= 0.0D) {
/* 124 */         itemData.ADDVAL_PARTRATE = MathUtil.divide(Double.valueOf(itemData.ADDVAL), Double.valueOf(this.Increase_SumVal)).doubleValue();
/*     */       } else {
/* 126 */         itemData.ADDVAL_PARTRATE = MathUtil.divide(Double.valueOf(itemData.ADDVAL), Double.valueOf(this.Decline_SumVal)).doubleValue();
/*     */       }
/*     */     }
/*     */     
/* 130 */     sortItemData("ADDVAL", "ADDVAL_PARTINDEX");
/*     */     
/* 132 */     DimItemData firstIncreaseValItem = (DimItemData)this.dimItemList.get(0);
/* 133 */     if (firstIncreaseValItem.DRATE < 0.0D) {
/* 134 */       this.firstIncrease_RateIndex = -1;
/*     */     }
/*     */     else {
/* 137 */       this.firstIncrease_Code = firstIncreaseValItem.ITEMCODE;
/* 138 */       this.firstIncrease_ValRate = firstIncreaseValItem.ADDVAL_PARTRATE;
/* 139 */       this.firstIncrease_ValScope = firstIncreaseValItem.ADDVAL;
/* 140 */       this.firstIncrease_Rate = firstIncreaseValItem.DRATE;
/* 141 */       int index = 0;
/* 142 */       index = 0;
/* 143 */       for (int i = 0; i < this.dimItemList.size(); i++) {
/* 144 */         DimItemData itemData = (DimItemData)this.dimItemList.get(i);
/* 145 */         if (itemData.DRATE > firstIncreaseValItem.DRATE) {
/* 146 */           index++;
/*     */         }
/*     */       }
/* 149 */       this.firstIncrease_RateIndex = index;
/* 150 */       this.firstIncrease_RatePos = MathUtil.divide(Double.valueOf(index + 0.0D), Double.valueOf(this.IncreaseMemberNum + 0.0D)).doubleValue();
/*     */     }
/*     */     
/* 153 */     DimItemData firstDeclineValItem = (DimItemData)this.dimItemList.get(this.dimItemList.size() - 1);
/* 154 */     if (firstDeclineValItem.DRATE > 0.0D) {
/* 155 */       this.firstDecline_RateIndex = -1;
/*     */     }
/*     */     else {
/* 158 */       this.firstDecline_Code = firstDeclineValItem.ITEMCODE;
/* 159 */       this.firstDecline_ValRate = firstDeclineValItem.ADDVAL_PARTRATE;
/* 160 */       this.firstDecline_ValScope = firstDeclineValItem.ADDVAL;
/* 161 */       this.firstDecline_Rate = firstDeclineValItem.DRATE;
/* 162 */       int index = 1;
/* 163 */       for (int i = 0; i < this.dimItemList.size(); i++) {
/* 164 */         DimItemData itemData = (DimItemData)this.dimItemList.get(i);
/* 165 */         if (itemData.DRATE < firstDeclineValItem.DRATE) {
/* 166 */           index++;
/*     */         }
/*     */       }
/* 169 */       this.firstDecline_RateIndex = index;
/* 170 */       this.firstDecline_RatePos = MathUtil.divide(Double.valueOf(index + 0.0D), Double.valueOf(this.DeclineMemberNum + 0.0D)).doubleValue();
/*     */     }
/* 172 */     if ((where == null) || (where.equals(""))) {
/* 173 */       saveDimInfotoDb();
/* 174 */       saveDimItemtoDb();
/*     */     }
/*     */   }
/*     */   
/* 178 */   private void sortItemData(String sortField) { Comparator comp = new DimItemSort(sortField);
/* 179 */     Collections.sort(this.dimItemList, comp);
/* 180 */     for (int i = 0; i < this.dimItemList.size(); i++) {
/* 181 */       DimItemData itemData = (DimItemData)this.dimItemList.get(i);
/* 182 */       System.out.println(itemData.ITEMCODE + "," + itemData.getFieldVal(sortField) + ",排名:" + (i + 1));
/*     */     }
/*     */   }
/*     */   
/*     */   private void sortItemData(String sortField, String outfield) {
/* 187 */     Comparator comp = new DimItemSort(sortField);
/* 188 */     Collections.sort(this.dimItemList, comp);
/* 189 */     for (int i = 0; i < this.dimItemList.size(); i++) {
/* 190 */       DimItemData itemData = (DimItemData)this.dimItemList.get(i);
/* 191 */       itemData.setFieldVal(outfield, Integer.valueOf(i + 1));
/* 192 */       System.out.println(itemData.ITEMCODE + "," + sortField + "," + itemData.getFieldVal(sortField) + ",排名:" + (i + 1) + "," + itemData.getFieldVal(outfield));
/*     */     }
/* 194 */     JsonHelper jsonHelper = JsonHelper.getInstance();
/* 195 */     System.out.println(jsonHelper.write(this));
/*     */   }
/*     */   
/* 198 */   private void saveDimInfotoDb() { JdbcTemplate jdbcTemplate = new JdbcTemplate("");
/* 199 */     String sql = "insert into MINDER_OLAPDIM_CHKINFO(OLAPCODE,OPTIME,DIMCODE,MEMBERNUM,SAMPLEMEMBERNUM,OPSAMPLEMEMBERNUM,ADDMEMBERNUM,ADDMEMBER_VAL,ADDMEMBER_VALRATE,DELMEMBERNUM,DELMEMBER_VAL,DELMEMBER_VALRATE,INCREASEMEMBERNUM,INCREASE_SUMVAL,FIRSTINCREASE_CODE,FIRSTINCREASE_RATE,FIRSTINCREASE_VALSCOPE,FIRSTINCREASE_VALRATE,FIRSTINCREASE_RATEINDEX,FIRSTINCREASE_RATEPOS,DECLINEMEMBERNUM,DECLINE_SUMVAL,FIRSTDECLINE_CODE,FIRSTDECLINE_RATE,FIRSTDECLINE_VALSCOPE,FIRSTDECLINE_VALRATE,FIRSTDECLINE_RATEINDEX,FIRSTDECLINE_RATEPOS,COMPARETIME) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
/*     */     
/*     */ 
/*     */ 
/*     */ 
/*     */     try
/*     */     {
/* 206 */       jdbcTemplate.update(sql, new Object[] { this.olapInfo.olapCode, this.olapInfo.taskid, this.dimid, 
/*     */       
/*     */ 
/*     */ 
/* 210 */         Integer.valueOf(this.memberNum), 
/* 211 */         Integer.valueOf(this.sampleMemberNum), 
/* 212 */         Integer.valueOf(this.opsampleMemberNum), 
/* 213 */         Integer.valueOf(this.AddMemberNum), 
/* 214 */         Double.valueOf(this.AddMember_Val), 
/* 215 */         Double.valueOf(this.AddMember_ValRate), 
/* 216 */         Integer.valueOf(this.DelMemberNum), 
/* 217 */         Double.valueOf(this.DelMember_Val), 
/* 218 */         Double.valueOf(this.DelMember_ValRate), 
/* 219 */         Integer.valueOf(this.IncreaseMemberNum), 
/* 220 */         Double.valueOf(this.Increase_SumVal), this.firstIncrease_Code, 
/*     */         
/* 222 */         Double.valueOf(this.firstIncrease_Rate), 
/* 223 */         Double.valueOf(this.firstIncrease_ValScope), 
/* 224 */         Double.valueOf(this.firstIncrease_ValRate), 
/* 225 */         Integer.valueOf(this.firstIncrease_RateIndex), 
/* 226 */         Double.valueOf(this.firstIncrease_RatePos), 
/* 227 */         Integer.valueOf(this.DeclineMemberNum), 
/* 228 */         Double.valueOf(this.Decline_SumVal), this.firstDecline_Code, 
/*     */         
/* 230 */         Double.valueOf(this.firstDecline_Rate), 
/* 231 */         Double.valueOf(this.firstDecline_ValScope), 
/* 232 */         Double.valueOf(this.firstDecline_ValRate), 
/* 233 */         Integer.valueOf(this.firstDecline_RateIndex), 
/* 234 */         Double.valueOf(this.firstDecline_RatePos), this.olapInfo.ptaskid });
/*     */ 
/*     */     }
/*     */     catch (Exception sqlex)
/*     */     {
/* 239 */       logger.info("保存维度信息时出错:信息:" + sqlex.toString() + "sql:" + sql);
/* 240 */       sqlex.printStackTrace();
/*     */     }
/*     */   }
/*     */   
/*     */   private void saveDimItemtoDb() {
/* 245 */     JdbcTemplate jdbcTemplate = new JdbcTemplate("");
/* 246 */     String sql = "insert into MINDER_OLAPDIM_CHKDETAIL(OLAPCODE,OPTIME,DIMCODE,ITEMCODE,VAL,PVAL,DRATE,ADDVAL,ADDVAL_PARTRATE,ADDVAL_PARTINDEX,VAL_PARTRATE,VAL_PARTINDEX,VAL_PARTINDEXCHG,ISNEW,OP_SUMRATE,DRATE_INDEX,ITEMNAME,COMPARETIME) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
/*     */     
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/* 252 */     for (int i = 0; i < this.dimItemList.size(); i++) {
/* 253 */       DimItemData item = (DimItemData)this.dimItemList.get(i);
/*     */       try {
/* 255 */         jdbcTemplate.update(sql, new Object[] { this.olapInfo.olapCode, this.olapInfo.taskid, this.dimid, item.ITEMCODE, 
/*     */         
/*     */ 
/* 258 */           Double.valueOf(item.VAL), Double.valueOf(item.PVAL), Double.valueOf(item.DRATE), Double.valueOf(item.ADDVAL), Double.valueOf(item.ADDVAL_PARTRATE), 
/* 259 */           Integer.valueOf(item.ADDVAL_PARTINDEX), MathUtil.divide(Double.valueOf(item.VAL), Double.valueOf(this.val)), 
/* 260 */           Integer.valueOf(item.VAL_INDEX), Integer.valueOf(item.VAL_INDEXCHG), item.ISNEW, 
/* 261 */           Double.valueOf(item.OP_SUMRATE), Integer.valueOf(item.DRATE_INDEX), item.ITEMCODE, this.olapInfo.ptaskid });
/*     */       }
/*     */       catch (Exception sqlex)
/*     */       {
/* 265 */         logger.info("保存维度成员信息时出错:信息:" + sqlex.toString() + "sql:" + sql);
/* 266 */         sqlex.printStackTrace();
/*     */       }
/*     */     }
/*     */   }
/*     */   
/*     */   protected static double getDouble(Object val) {
/* 272 */     try { if (val == null)
/* 273 */         return 0.0D;
/* 274 */       if ((val instanceof BigDecimal))
/* 275 */         return ((BigDecimal)val).doubleValue();
/* 276 */       if ((val instanceof Integer))
/* 277 */         return ((Integer)val).doubleValue();
/* 278 */       if ((val instanceof Float))
/* 279 */         return ((Float)val).doubleValue();
/* 280 */       if ((val instanceof String)) {
/* 281 */         String valStr = (String)val;
/* 282 */         if (valStr.indexOf(".") < 0)
/* 283 */           return Integer.parseInt(valStr);
/* 284 */         return Double.parseDouble(valStr); }
/* 285 */       if ((val instanceof Long)) {
/* 286 */         return Double.valueOf(val.toString()).doubleValue();
/*     */       }
/*     */       
/* 289 */       return ((Double)val).doubleValue();
/*     */ 
/*     */     }
/*     */     catch (Exception e)
/*     */     {
/* 294 */       e.printStackTrace(); }
/* 295 */     return -999.0D;
/*     */   }
/*     */ }


/* Location:              C:\Users\my\.m2\repository\com\asiainfo\dacp\dacp-dataos\1.0.0\dacp-dataos-1.0.0.jar!\com\asiainfo\dacp\stat\olapcheck\DimInfo.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */